package 反转链表;

public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        ListNode head = new ListNode(5);
        ListNode temp = head.next;


        for(int i  = 5; i > 1 ;i--){
            ListNode t = new ListNode(i - 1);
            temp = t;
        }

        System.out.println(head);


    }

    public ListNode reverseList(ListNode head) {
        ListNode current = null;
        pingjie(current,head);
        return current;
    }

    public void pingjie(ListNode current,ListNode head){
        if(head.next != null){
            pingjie(current,head.next);
        }
        if(current == null){
            current = head;
        }
        else {
            current.next = head;
        }

    }

    public static class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
}
